package com.ruoyi.meeting.util;

import cn.hutool.http.HttpRequest;
import cn.hutool.http.HttpUtil;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import com.ruoyi.common.core.constant.Constants;
import com.ruoyi.meeting.domain.constant.MapConstant;


public class MapUtil {

    /**
     * 获取导航路径
     * @param startLng
     * @param startLat
     * @param endLng
     * @param endLat
     * @param type
     * @return
     */
    public static Object getNavigationPath(Double startLng,Double startLat,Double endLng,Double endLat,Integer type){
        String baseUrl = MapConstant.NAVIGATIONBASEURL + MapConstant.WALKINGPATH;
        if(type == MapConstant.DRIVING){
            baseUrl = MapConstant.NAVIGATIONBASEURL + MapConstant.DRIVINGPATH;
        }
        JSONObject result = null;
        try{
            String resultStr = HttpRequest.get(baseUrl)
                    .form("origin", startLng + "," + startLat)
                    .form("destination", endLng + "," + endLat)
                    .form("key", MapConstant.APIKEY)
                    .execute().body();
            result = JSONUtil.parseObj(resultStr);
        } catch (Exception e){
            throw new RuntimeException("获取路径失败");
        }
        return result;
    }

}
